import { Rect, Point, Direction} from '@topology/core';



function myShapeNode(ctx, node) {
  ctx.beginPath();
  console.log("我的图形开始拖到画布上");
  var offsetX = node.rect.width / 7;
  ctx.moveTo(node.rect.x + offsetX, node.rect.y);
  ctx.lineTo(node.rect.ex, node.rect.y);
  ctx.lineTo(node.rect.x + node.rect.width - offsetX, node.rect.ey);
  ctx.lineTo(node.rect.x, node.rect.ey);
  ctx.closePath();
  (node.fillStyle || node.bkType) && ctx.fill();
  ctx.stroke();
}

function myShapeAnchors(node) {
  console.log(Direction);
  node.anchors.push(new Point(node.rect.x + node.rect.width / 14, node.rect.y + node.rect.height / 2, Direction.Left));
  node.anchors.push(new Point(node.rect.x + (node.rect.width * 4) / 7, node.rect.y, Direction.Up));
  node.anchors.push(new Point(node.rect.x + (node.rect.width * 13) / 14, node.rect.y + node.rect.height / 2, Direction.Right));
  node.anchors.push(new Point(node.rect.x + (node.rect.width * 3) / 7, node.rect.ey, Direction.Bottom));
}

function myShapeIconRect(node) {
  node.iconRect = new Rect(0, 0, 0, 0);
}
function myShapeTextRect(node) {
  node.textRect = new Rect(node.rect.x + node.rect.width / 7, node.rect.y, (node.rect.width * 5) / 7, node.rect.height);
  node.fullTextRect = node.textRect;
}

export function register() {
  window.Le5leTopology.registerNode('tttt', myShapeNode, myShapeAnchors, myShapeIconRect, myShapeTextRect);
}
